{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Necessary conditions for Graph partition \n",
    "### Install pyQUBO from Recruit Communications Co. Ltd.\n",
    "    pip install pyqubo\n",
    "### Install openJij from Jij Inc.  (startup from Tohoku University)\n",
    "    pip install openjij"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Add networkx for dealing with graph theory"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "        pip install networkx"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Solve Graph Partition"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### import pyQUBO, openJij and numpy"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pyqubo  import Array,Constraint, Placeholder\n",
    "import openjij as jij\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Array, Constrains and Placeholders are convenient classes from pyQUBO"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### import networkx"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import networkx as nx"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Prepare some graph"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "nodes = [0, 1, 2, 3, 4, 5]\n",
    "edges = [\n",
    "    (0, 1), (1, 2), (2, 0), \n",
    "    (1, 5), (0, 3),\n",
    "    (3, 4), (4, 5), (5, 1)\n",
    "    ]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Set nodes and edges on Graph G"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "G = nx.Graph()\n",
    "G.add_nodes_from(nodes)\n",
    "G.add_edges_from(edges)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "nx.draw_networkx(G)\n",
    "plt.axis(\"off\")\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Prepare spin variables"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "N = 6\n",
    "vartype = \"SPIN\"\n",
    "x = Array.create(\"x\",shape=N,vartype=vartype)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\"x\" is name of variables  \n",
    "shape specifies the shape of variables as vector, matrix, or...  \n",
    "vartype selects -1 or 1 by \"SPIN\" and 0 or 1by \"BINARY\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Array([Spin(x[0]), Spin(x[1]), Spin(x[2]), Spin(x[3]), Spin(x[4]), Spin(x[5])])\n"
     ]
    }
   ],
   "source": [
    "print(x)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Define cost function"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "E1 = Constraint((np.sum(x))**2,\"equal\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "E2 = 0\n",
    "for e in edges:\n",
    "    E2 += 0.5*(1-x[e[0]]*x[e[1]])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "Lam = Placeholder('Lam')\n",
    "E_cost = Lam*E1+E2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Compile the cost function"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "model = E_cost.compile()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Get qubo matrix"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "feed_dict = {'Lam': 5.0}\n",
    "h,J, offset = model.to_ising(feed_dict=feed_dict)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Prepare simulation of quantum annealing"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "#simulated quantum annealing\n",
    "sampler = jij.SQASampler(beta=10.0, gamma=1.0, trotter=4, num_sweeps=100)\n",
    "#simulated annealing\n",
    "#sampler = jij.SASampler(num_sweeps=1000)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This is done by quantum Monte-Carlo simulation  \n",
    "gamma = strength of quantum fluctuation  \n",
    "trotter = Trotter number  \n",
    "num_sweeps = length of MCS"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Let's simulate quantum annealing"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "response = sampler.sample_ising(h,J)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Show results"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  x[0] x[1] x[2] x[3] x[4] x[5] energy num_oc.\n",
      "0   -1   -1   -1   +1   +1   +1  -31.0       1\n",
      "['SPIN', 1 rows, 1 samples, 6 variables]\n"
     ]
    }
   ],
   "source": [
    "print(response)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[-1, -1, -1,  1,  1,  1]], dtype=int8)"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "response.record[\"sample\"]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### show resulting graph"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAV0AAADnCAYAAAC9roUQAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+j8jraAAAgAElEQVR4nO3deXydVbX/8c86SToPDG0NUKC0EOigBQWUeZDIC2VQIKLI9EP4iVAQRMEBFRUHZlAR4coFVEDIvUABUQxlUERAZihDWqBQhlAKFELn5Kz7x35CMzbTOWc/55zv+/XKi5Lz5HlWh6zss/bae5u7IyIihZGJHYCISDlR0hURKSAlXRGRAlLSFREpICVdEZECUtIVESmgytgBiKRdtqnGgB2AU4FPAqOAVcAbwCXAtZnqxg/iRSjFxNSnK9KzbFPNgcA5QDUwnK7vDj9IPvcH4FuZ6salhY1Qio2SrkgPsk01PwC+A4zow+UrgBeBPTLVjYvyGpgUNSVdkW5km2pOBH5J3xJum9VAI/BJjXilJ5pIE+kk21QzBTib/iVcgCpgCvCTnAclJSOVI91sU00VMBVYF2gF3gIaM9WN6QtWSk62qeYi4OvAkM6vHX5CE3fdt4yly5zqCRV86/h1OeYrYztf1gxMyFQ3rihAuFJkUpV0s001E4HjgBOACiCbvFRJSLznAH/KVDc2x4lQSl22qWY4sIjQodDF3OdXsvmkKoYOzfDcvFXsedCr3PrHDfnEzGHtL2sGTshUN/6xACFLkUlFeSHbVJPJNtVcAMwjtOWsA4wGxiYfI4FJwLlAU7ap5iuRQpXStzdrfth3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+mKSLn5F2A9vfgcj7GUZmayExXW0wI1VgB/GsjD1b0gImWnNlN3PjALGNL+88t9Kf/ir2TIYO3y8lZ8gg1sk/aXrgC2aMjWv9rfZyvpikjZqc3UbUbYknLYAL68FZjTkK3feyDPVnlBRMpOQ7b+JeCXwNIBfHkz8PWBPltJV0TK1U+APxD2UuiLLPAeUNuQrX9xoA9V0hWRstSQrXfgBOC7hNFrcw+XthAS8xOEpb8PD+a5qumKSNmrzdQNBQ4GTgemE+q2FYTTI64DLmrI1j+Vi2cp6YqItFObqcsAo4BVDdn6Fbm+v5KuiEgBqaYrIlJASroiIgWkpCsiUkBKuiIiBaSkKyJSQEq6IiIF9H+Bkaa6xlfKrgAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "spin = response.record[\"sample\"][0]\n",
    "node_colors = [spin[node]>0 for node in G.nodes()]\n",
    "\n",
    "nx.draw_networkx(G,node_color=node_colors)\n",
    "plt.axis(\"off\")\n",
    "plt.show()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
